<?php
// $Id: storminvoice.views.inc,v 1.1.2.6 2010/09/21 21:53:29 juliangb Exp $

function storminvoice_views_data() {
  // Invoice core fields
  $data['storminvoice']['table']['group']  = t('Storm Invoice');
  $data['storminvoice']['table']['join'] = array(
    'node' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
  );
  
  $data['storminvoice']['number'] = array(
    'title' => t('Number'),
    'help' => t('Storm Invoice Number'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  $data['storminvoice']['reference'] = array(
    'title' => t('Reference'),
    'help' => t('Storm Invoice Reference'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );
  
  $data['storminvoice']['organization_nid'] = array(
    'title' => t('Organization'),
    'help' => t('Invoice -> Organization'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Invoice -> Organization'),
    ),
  );
  
  $data['storminvoice']['organization_title'] = array(
    'title' => t('Organization'),
    'help' => t('Storm Invoice Organization (title only)'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['storminvoice']['project_nid'] = array(
    'title' => t('Project'),
    'help' => t('Invoice -> Project'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Invoice -> Project'),
    ),
  );
  
  $data['storminvoice']['project_title'] = array(
    'title' => t('Project'),
    'help' => t('Storm Invoice Project (title only)'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

  $data['storminvoice']['requestdate'] = array(
    'title' => t('Request Date'),
    'help' => t('Storm Invoice Request Date'),
    'field' => array(
      'click sortable' => TRUE,
      'handler' => 'views_handler_field_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ),
  );
  
  $data['storminvoice']['duedate'] = array(
    'title' => t('Due Date'),
    'help' => t('Storm Invoice Due Date'),
    'field' => array(
      'click sortable' => TRUE,
      'handler' => 'views_handler_field_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ),
  );

  $data['storminvoice']['paymentdate'] = array(
    'title' => t('Payment Date'),
    'help' => t('Storm Invoice Payment Date'),
    'field' => array(
      'click sortable' => TRUE,
      'handler' => 'views_handler_field_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ),
  );
  
  $data['storminvoice']['amount'] = array(
    'title' => t('Amount'),
    'help' => t('Storm Invoice Amount'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice']['tax1'] = array(
    'title' => t('Tax 1'),
    'help' => t('Storm Invoice Tax 1'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  $data['storminvoice']['tax2'] = array(
    'title' => t('Tax 2'),
    'help' => t('Storm Invoice Tax 2'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice']['total'] = array(
    'title' => t('Total'),
    'help' => t('Storm Invoice Total'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice']['totalcustomercurr'] = array(
    'title' => t('Total in Customer Currency'),
    'help' => t('Storm Invoice Total in Customer Currency'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice']['taxexempt'] = array(
    'title' => t('Tax Exempt'),
    'help' => t('Storm Invoice Tax Exempt'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  // Invoice items
  $data['storminvoice_items']['table']['group']  = t('Storm Invoice Item');
  $data['storminvoice_items']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'invoice_nid',
    ),
  );
  
  $data['storminvoice_items']['invoice_nid'] = array(
    'title' => t('Invoice'),
    'help' => t('Invoiceitem -> Invoice'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Invoiceitem -> Invoice'),
    ),
  );

  $data['storminvoice_items']['weight'] = array(
    'title' => t('Weight'),
    'help' => t('Storm Invoiceitem Weight'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice_items']['amount'] = array(
    'title' => t('Amount'),
    'help' => t('Storm Invoiceitem Amount'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice_items']['tax1percent'] = array(
    'title' => t('Tax 1 Percent'),
    'help' => t('Storm Invoiceitem Tax 1 Percent'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  $data['storminvoice_items']['tax2percent'] = array(
    'title' => t('Tax 2 Percent'),
    'help' => t('Storm Invoiceitem Tax 2 Percent'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  $data['storminvoice_items']['tax1'] = array(
    'title' => t('Tax 1'),
    'help' => t('Storm Invoiceitem Tax 1'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );

  $data['storminvoice_items']['tax2'] = array(
    'title' => t('Tax 2'),
    'help' => t('Storm Invoiceitem Tax 2'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  $data['storminvoice_items']['total'] = array(
    'title' => t('Total'),
    'help' => t('Storm Invoiceitem Total'),
    'field' => array(
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );
  
  return $data;
}

function storminvoice_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'stormattribute'),
    ),
    'handlers' => array(
      'stormattribute_handler_filter_attributes_domain' => array(
        'parent' => 'views_handler_filter_in_operator',
      ),
    ),
  );
}
